﻿using System;
using System.Collections.ObjectModel;
using System.Reflection;
using System.IO;

namespace Jerry.DroidBuilder.Common
{
    public class RomItem : NotifyPropertyChangedObject
    {
        public RomItem(bool isDirectory, string fileName)
        {
            IsDirectory = isDirectory;
            SubItems = new ObservableCollection<RomItem>();

            Name = Path.GetFileName(fileName);
            FileName = fileName;

            IsApk = Name.EndsWith(".apk", StringComparison.OrdinalIgnoreCase);
            IsJar = Name.EndsWith(".jar", StringComparison.OrdinalIgnoreCase);
            IsOdex = Name.EndsWith(".odex", StringComparison.OrdinalIgnoreCase);
            IsBootImage = Name.Equals("boot.img", StringComparison.OrdinalIgnoreCase);

            SystemInfo = IsDirectory ? new DirectoryInfo(fileName) as FileSystemInfo : new FileInfo(fileName) as FileSystemInfo;
        }

        public bool IsApk { get; private set; }
        public bool IsJar { get; private set; }
        public bool IsOdex { get; private set; }
        public bool IsBootImage { get; private set; }

        public bool IsDirectory { get; private set; }

        /// <summary>
        /// Specified for apk/jar file.
        /// The extracted file will put in a separated directory.
        /// </summary>
        public string OutputDirectory { get; set; }

        public string Name { get; private set; }

        public string FileName { get; private set; }

        public FileSystemInfo SystemInfo { get; private set; }

        public ObservableCollection<RomItem> SubItems { get; private set; }
    }
}
